package com.hqj.demo.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class RoleAop {

    @Pointcut("execution(* com.hqj.demo.service.AppleServiceI.add(..))")
    public void pointCut(){

    }
    @Before("pointCut()")
    public void before(){
        System.out.println("前置通知");
    }

    @After("pointCut()")
    public void after(){
        System.out.println("后置通知");
    }

    @AfterReturning(pointcut = "pointCut()",returning = "obj")
    public void afterReturning(Object obj){
        System.out.println("返回值通知,返回内容:"+obj);
    }

    @AfterThrowing(pointcut = "pointCut()",throwing = "ex")
    public void afterThrowing(Throwable ex){
        System.out.println("发生异常通知，异常内容:"+ex);
    }

    @Around("pointCut()")
    public Object aroud(ProceedingJoinPoint pjp){
        Object obj = null;
        System.out.println("环绕的开始");
        try {
            obj = pjp.proceed();
            System.out.println("环绕的结果:"+obj);
        }catch (Throwable a){
            a.printStackTrace();
        }
        System.out.println("环绕的结束");
        return obj;
    }

}
